package App.OOSerVice.service.thread.manage;

import App.OOSerVice.service.thread.StoCThread;

import java.util.HashMap;
import java.util.Iterator;

public class ManageStoCThread {
    private static HashMap<String, StoCThread> manage = new HashMap<>();

    public static void addStoCThread(String userId, StoCThread stoCThread) {
        manage.put(userId, stoCThread);
    }

    public static StoCThread getStoCThread(String userId) {
        StoCThread stoCThread = manage.get(userId);
        return stoCThread;
    }

    //返回在线用户列表
    public static String getOnlineList() {
        Iterator<String> iterator = (manage.keySet()).iterator();
        StringBuilder returnData = new StringBuilder();
        while (iterator.hasNext()) {
            returnData.append(iterator.next().toString()).append(" ");
        }
        return returnData.toString();
    }

    public static void deleteStoCThread(String userId) {
        manage.remove(userId);
    }

    public static HashMap<String, StoCThread> getManage() {
        return manage;
    }
}
